/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package deatax.display.miniboard;

import deatax.display.Texture;
import javax.media.opengl.GL2;

/**
 *
 * @author nrechten
 */
public class DiceRenderer {

    private static Texture DICE_TEXTURE = new Texture("tiles/dice.png");
    public static float[] vertex = new float[]{
        -1,-1,-1, 1,-1,-1,  1,1,-1, -1,1,-1, -1,-1,1, 1,-1,1, 1,1,1, -1,1,1
    };
    public static int[] order = new int[]{
        2,3,0,4,5,6
    };
    public static float[] texture = new float[]{
        0,0.5f, 0,1, 0,0.5f, 0,0, 0.5f,0, 1,0, 0.5f,0, 0.5f,1, 0,1, 0.5f,1, 1,1, 1,0.5f, 1,0, 1,0.5f,
    };


    public void draw(GL2 gl){

        gl.glEnable(GL2.GL_TEXTURE_2D);
        gl.glDisable(GL2.GL_CULL_FACE);
        gl.glColor3f(1,1,1);

        DICE_TEXTURE.bind(gl);

        gl.glBegin(GL2.GL_TRIANGLE_FAN);
        gl.glTexCoord2f(0.5f,0.5f);
        gl.glVertex3fv(vertex,3);
        for (int i = 0, o = 0; i < 14; i++) {
            if(i == 7){
                gl.glEnd();
                gl.glBegin(GL2.GL_TRIANGLE_FAN);
                gl.glTexCoord2f(0.5f,0.5f);
                gl.glVertex3fv(vertex,21);
                o = 2;
            }
            gl.glTexCoord2fv(texture, i*2);
            gl.glVertex3fv(vertex, order[(i+o)%6]*3);
        }
        gl.glEnd();

        gl.glDisable(GL2.GL_TEXTURE_2D);
    }
}
